import request from '@/utils/request'

export const tutoringService = {
    // 发布家教信息
    publishTutoring(data) {
        return request.post('/tutoring/publish', data)
    },

    // 获取所有可用的家教信息（包含教师认证信息）
    getAllTutoring() {
        return request.get('/tutoring/list-with-teacher-info')
    },

    // 获取学生已确认预约的老师的课程
    getStudentConfirmedTutorings() {
        return request.get('/tutoring/student-confirmed')
    },

    // 获取教师发布的家教信息
    getTeacherTutoring() {
        return request.get('/tutoring/teacher')
    },

    // 更新家教信息状态
    updateTutoringStatus(id, status) {
        return request.put(`/tutoring/status/${id}?status=${status}`)
    },

    // 更新家教信息
    updateTutoring(data) {
        return request.put('/tutoring/update', data)
    },

    // 创建预约
    createBooking(data) {
        return request.post('/tutoring/booking', data)
    },

    // 获取教师收到的预约
    getTeacherBookings() {
        return request.get('/tutoring/booking/teacher')
    },

    // 获取学生发出的预约
    getStudentBookings() {
        return request.get('/tutoring/booking/student')
    },

    // 处理预约
    handleBooking(id, status) {
        return request.put(`/tutoring/booking/status/${id}?status=${status}`)
    },

    // 家教时间安排相关
    createSchedule(data) {
        return request.post('/tutoring/schedule/create', data)
    },

    getTeacherSchedules() {
        return request.get('/tutoring/schedule/teacher')
    },

    getStudentSchedules() {
        return request.get('/tutoring/schedule/student')
    },

    getScheduleDetail(id) {
        return request.get(`/tutoring/schedule/${id}`)
    },

    updateScheduleStatus(id, status) {
        return request.put(`/tutoring/schedule/${id}/status?status=${status}`)
    },

    submitFeedback(id, feedback, rating) {
        return request.put(`/tutoring/schedule/${id}/feedback?feedback=${encodeURIComponent(feedback)}&rating=${rating}`)
    },

    // 获取家教预约详情
    getTutoringBooking(id) {
        return request.get(`/tutoring/booking/${id}`)
    },

    // 教师创建课程安排
    createTeacherSchedule(data) {
        return request.post('/tutoring/schedule/teacher/create', data)
    },

    // 学生确认/取消课程安排
    updateStudentScheduleStatus(id, status) {
        return request.put(`/tutoring/schedule/student/${id}/status?status=${status}`)
    },

    // 获取学生待确认的课程安排
    getStudentPendingSchedules() {
        return request({
            url: '/tutoring/schedule/student/pending',
            method: 'get'
        })
    },

    // 删除家教预约
    deleteBooking(id) {
        return request.delete(`/tutoring/booking/${id}`)
    },

    // 删除课程时间安排
    deleteSchedule(id) {
        return request.delete(`/tutoring/schedule/${id}`)
    },

    // 检查课程支付状态
    checkSchedulePaymentStatus(scheduleId) {
        return request({
            url: `/tutoring/schedule/${scheduleId}/payment-status`,
            method: 'get'
        })
    },

    // 管理员获取所有家教信息
    adminGetAllTutoring() {
        return request.get('/tutoring/admin/list')
    },

    // 管理员审核家教信息
    adminAuditTutoring(id, status) {
        return request.put(`/tutoring/admin/audit/${id}`, null, {
            params: { status }
        })
    },

    // 检查课程时间冲突
    checkTimeConflict(data) {
        return request.post('/tutoring/schedule/check-conflict', data)
    },

    // 获取某个时间范围内的所有课程安排
    getSchedulesByDateRange(startDate, endDate) {
        return request.get(`/tutoring/schedule/range?startDate=${startDate}&endDate=${endDate}`)
    }
}

// 获取教师的预约列表
export function getTeacherBookings() {
    return request({
        url: '/tutoring/booking/teacher',
        method: 'get'
    })
} 